#include <iostream>
#include <vector>

#include "List.hpp"

using namespace std;
using namespace cs540;

int main(){

	List<int> lt;
	List<int> lt1;
	List<int> lt2;
	//List<int> lt1(lt);
	//lt1=lt;
	cout << "lt Size : " << lt.size() << endl;
	
	List<int>::Iterator it;
	List<int>::Iterator it1;

	//it = it1;
	it = lt.begin();
	it = lt.insert(it, 10);
	it = lt.insert(it, 11);
	it = lt.insert(it, 12);

	it1 = lt1.begin();
	it1 = lt1.insert(it1, 50);
	it1 = lt1.insert(it1, 51);
	it1 = lt1.insert(it1, 52);

	cout << "it data : " <<*it << endl;	
	
	it = lt.begin();
	cout << "begin it data : " <<*it << endl;	
	cout << "\n\n";
	it1 = lt.end();
	//cout << "\n\nend it data : " <<*it1 << endl;	

	cout << "List size : " << lt.size() << endl;
	int &i = lt.front();
	//i = 100;
	cout << "List front : " << lt.front() << endl;
	cout << "List back : " << lt.back() << endl;

	lt.push_front(9);
	cout << "List begin  : " <<*(lt.begin()) << endl;	

	lt.push_back(13);
	//cout << "List end  : " <<*(lt.end()) << endl;	

	//it = lt.erase(lt.end());
	//cout << "List end  : " <<*it << endl;	
	//cout << "List end  : " <<*(lt.end()) << endl;	
	

	//lt.pop_back();
	//cout << "List end  : " <<*(lt.end()) << endl;	
	
	//lt.clear();

	// duplicate data 
	/*lt.push_back(13);
	lt.push_front(13);
	lt.push_back(13);
	*/

	//lt.remove(13);

	lt.unique();
	cout << "\n";
	it = lt.begin();
	cout << "List begin  : " <<*it << endl;	
	it1 = it++;
	cout << "next element(int)  : " <<*it1 << endl;	
	it = lt.begin();
	it1 = ++it;
	cout << "next element  : " <<*it1 << endl;	
	//cout << "List end  : " <<*(lt.end()) << endl;	

	cout << "\n\nBefore splice : Printing all elements\n" ;
	for (it = lt.begin(); it != lt.end(); ++it)
		cout << *it << " " ;

	cout << endl;

	it = lt.end();
	//cout << "===================================List end  : " <<*it << endl;	
	cout << "===================================List end  : " <<*(++it) << endl;	


	it = lt.begin();
	//it++;

	lt.splice(it, lt1, lt1.begin());

	cout << "\n\nAfter splice (lt) : Printing all elements\n" ;
	for (it = lt.begin(); it != lt.end(); ++it)
		cout << *it << " " ;

	cout << endl;

	it = lt.end();
	//cout << "===================================List end  : " <<*it << endl;	
	cout << "===================================List end  : " <<*(++it) << endl;	

	cout << "\n\nAfter splice (lt1):Printing all elements\n" ;
	for (it = lt1.begin(); it != lt1.end(); ++it)
		cout << *it << " " ;

	cout << endl;

	it = lt1.end();
	//cout << "===================================List end  : " <<*it << endl;	
	cout << "===================================List end  : " <<*(++it) << endl;	

	lt2 = lt;
	
	cout << endl;

	List<int> lt3 (lt1);

	cout << "\n\nNew lt3 list : Printing all elements\n" ;
	for (it = lt3.begin(); it != lt3.end(); ++it)
		cout << *it << " " ;

	cout << endl;


	cout << "Compare : " << (lt1 < lt2) << " : true = " << true << endl;
	
	cout << "\nRange insert : \n";

	cout << "\n\nBefoe range insert lt1 list : Printing all elements\n" ;
	for (it = lt1.begin(); it != lt1.end(); ++it)
		cout << *it << " " ;

	cout << endl;

	std::vector<int> vt;
	vt.push_back(80);
	vt.push_back(81);
	vt.push_back(82);
	vt.push_back(83);

	std::vector<int>::iterator vit;

	cout << "\n\nBefoe range insert vt vector : Printing all elements\n" ;
	for (vit = vt.begin(); vit != vt.end(); ++vit)
		cout << *vit << " " ;

	cout << endl;


	lt1.insert(lt1.begin(), vt.begin(), --vt.end());
	
	cout << "\n\nAfter lt1 list : Printing all elements\n" ;
	for (it = lt1.begin(); it != lt1.end(); ++it)
		cout << *it << " " ;

	cout << "\n\nAfter lt1 list Reverse: Printing all elements\n" ;
	for (it = lt1.rbegin(); it != lt1.rend(); --it)
		cout << *it << " " ;


	// range erase:
	/*it = lt1.erase(lt1.begin(),--lt1.end());
	cout << "After erase : " << *it << endl ;
	
	cout << "\n\nAfter lt1 list range erase: Printing all elements\n" ;
	for (it = lt1.begin(); it != lt1.end(); ++it)
		cout << *it << " " ;

	*/

	/*cout << "\n\nBefore lt list range splice: Printing all elements\n" ;
	for (it = lt.begin(); it != lt.end(); ++it)
		cout << *it << " " ;

	lt.splice(lt.begin(), lt1, lt1.begin(), lt1.end());
	
	cout << "\n\nAfter lt list range splice: Printing all elements\n" ;
	for (it = lt.begin(); it != lt.end(); ++it)
		cout << *it << " " ;
	*/
	//lt2.clear();
	lt3.clear();
	lt2.push_back(11);
	lt2.push_back(11);
	lt2.push_back(11);
	lt2.push_back(11);
	lt2.push_back(12);
	lt2.push_back(12);
	lt2.push_back(12);
	lt2.push_back(13);
	
	lt3.push_back(50);
	lt3.push_back(9);
	lt3.push_back(10);
	lt3.push_back(11);
	lt3.push_back(12);
	lt3.push_back(13);
	//lt3.push_back(11);
	//lt3.push_back(12);

	cout << "\n\nPrinting all elements lt2 : l2 & l3 compare\n" ;
	for (it = lt2.begin(); it != lt2.end(); ++it)
		cout << *it << " " ;
	
	cout << "\n\nPrinting all elements lt3\n" ;
	for (it = lt3.begin(); it != lt3.end(); ++it)
		cout << *it << " " ;

	int ii = lt2 < lt3;
	cout << "\n\nSorting =>>>>>>>>>>>>>>>>: " << ii << endl << endl;

	//lt2.unique();
	cout << "\n\nPrinting all elements lt2 : Unique\n" ;
	for (it = lt2.begin(); it != lt2.end(); ++it)
		cout << *it << " " ;
	cout << endl;	

	cout << "Deleting first ele and checking iterator \n";

	//it = lt2.begin();
	//cout << "Before del : " << *it << endl;
	//lt2.pop_front();
	
	//cout << "After del : " << *it << endl;
	//cout << 

	/*int a(1);
	lt.insert(it, a);
	lt.erase(it);

	const int b(4);
	lt.push_front(b);
	lt.push_back(b);
	lt.pop_front();
	lt.pop_back();

	it++;
	++it;
	it--;
	--it;
	*/
}
